ตัวอย่างของ Hello world ในภาษาโปรแกรมต่าง ๆ ของ โปรแกรมเฮลโลเวิลด์

4GL - Computer Associates with Ingres/DB

message "Hello, World!" with style = popup;

ABAP - SAP AG

REPORT ZELLO.WRITE 'Hello, World!'.

ABC

WRITE "Hello, world!"

Ada

with Ada.Text_IO;procedure Hello isbegin   Ada.Text_IO.Put_Line ("Hello, world!") ;end Hello;

For explanation see wikibooks:Ada Programming:Basic.

ALGOL 68

In the popular upper-case stropping convention for bold words:

BEGIN    print (("Hello, World!", newline))END

or using prime stropping suitable for punch cards:

'BEGIN'    PRINT (("HELLO, WORLD!", NEWLINE))'END'

or minimally using the short form of begin and end, and implied newline at program termination:

( print ("Hello, World!") )

AmigaE

PROC main ()   WriteF ('Hello, World!') ;ENDPROC

APL

'Hello World'

AppleScript

See also GUI section.

return "Hello World!"

ASP

<%Response.Write ("Hello World")%>
or simply:
<%="Hello World" %>

ASP.NET

Response.Write ("Hello World")

Assembly language

Accumulator-only architecture: DEC PDP-8, PAL-III assembler

See the example section of the PDP-8 article.

First successful µP/OS combinations: Intel 8080/Zilog Z80, CP/M, RMAC assembler

bdos    equ    0005H    ; BDOS entry pointstart:  mvi    c,9      ; BDOS function: output string        lxi    d,msg$   ; address of msg        call   bdos        ret             ; return to CCPmsg$:   db    'Hello, world!$'end     start

Accumulator + index register machine: MOS Technology 6502, CBM KERNAL, ca65 assembler

MSG:   .ASCIIZ "Hello, world!"        LDX    #$F3@LP:    LDA    MSG-$F3,X ; load character        JSR    $FFD2     ; CHROUT (KERNAL) , output to current output device (screen)        INX        BNE    @LP       ;         RTS

Accumulator/Index microcoded machine: Data General Nova, RDOS

See the example section of the Nova article.

Expanded accumulator machine: Intel x86, DOS, TASM

MODEL   SMALLIDEALSTACK   100HDATASEG        MSG DB 'Hello, world!', 13, '$'CODESEGStart:        MOV AX, @data        MOV DS, AX        MOV DX, OFFSET MSG        MOV AH, 09H      ; DOS: output ASCII$ string        INT 21H        MOV AX, 4C00H        INT 21H        END Start

Expanded accumulator machine: Intel x86, Microsoft Windows, FASM

Assumes that enviromnent variable %fasminc% is set
format PE GUI 4.0include '%fasminc%\win32a.inc'section '.code' code readable executableinvoke MessageBox,0,hellomsg,hellolb,MB_OK+MB_ICONINFORMATIONinvoke ExitProcess,0section '.data' data readable writablehellomsg db 'Hello, World!',0hellolb db 'Hello World',0data importlibrary user32,'user32.dll',kernel32,'kernel32.dll'include '%fasminc%\apia\user32.inc'include '%fasminc%\apia\kernel32.inc'end data

Expanded accumulator machine: Intel x86, Linux, GAS

.datamsg:    .ascii     "Hello, world!\n"    len = . - msg.text    .global _start_start:    movl	$len,%edx    movl	$msg,%ecx    movl	$1,%ebx    movl	$4,%eax    int	$0x80    movl	$0,%ebx    movl	$1,%eax    int	$0x80

General-purpose fictional computer: MIX, MIXAL

TERM    EQU    19          console device no. (19 = typewriter)        ORIG   1000        start addressSTART   OUT    MSG (TERM)   output data at address MSG        HLT                halt executionMSG     ALF    "HELLO"        ALF    " WORL"        ALF    "D    "        END    START       end of program

General-purpose fictional computer: MMIX, MMIXAL

string BYTE "Hello, world!",#a,0 string to be printed (#a is newline and 0 terminates the string)

  Main  GETA   $255,string            get the address of the string in register 255        TRAP   0,Fputs,StdOut         put the string pointed to by register 255 to file StdOut        TRAP   0,Halt,0               end process

General-purpose-register CISC: DEC PDP-11, RT-11, MACRO-11

.MCALL  .REGDEF,.TTYOUT,.EXIT        .REGDEFHELLO:  MOV    #MSG,R1        MOVB   (R1) ,R0LOOP:  .TTYOUT        MOVB  + (R1) ,R0        BNE    LOOP       .EXITMSG:   .ASCIZ  /HELLO, WORLD!/       .END    HELLO

CISC on advanced multiprocessing OS: DEC VAX, VMS, MACRO-32

.title hello

        .psect    data, wrt, noexechan:   .blkw     1iosb:   .blkq     1term:   .ascid    "SYS$OUTPUT"msg:    .ascii    "Hello, world!"len =   . - msg        .psect    code, nowrt, exe        .entry    hello, ^m<>        ; Establish a channel for terminal I/O        $assign_s devnam=term, -                  chan=chan        blbc      r0, end        ; Queue the I/O request        $qiow_s   chan=chan, -                  func=#io$_writevblk, -                  iosb=iosb, -                  p1=msg, -                  p2=#len        ; Check the status and the IOSB status        blbc      r0, end        movzwl    iosb, r0        ; Return to operating systemend:    ret       .end       hello

RISC processor: ARM, RISC OS, BBC BASIC's in-line assembler

.program                  ADR R0,message         SWI "OS_Write0"         SWI "OS_Exit".message                  DCS "Hello, world!"         DCB 0          ALIGN

หรือเวอร์ชันย่อ (จาก qUE) ;

         SWI"OS_WriteS":EQUS"Hello, world!":EQUB0:ALIGN:MOVPC,R14

AutoHotkey

MsgBox, "Hello, World!"

Autoit

MsgBox (1,'','Hello, world!')

AWK

BEGIN { print "Hello, world!" }

Bash

echo Hello,\ world!

BASIC

General

The following example works for any ANSI/ISO-compliant BASIC implementation, as well as most implementations built into or distributed with microcomputers in the 1970s and 1980s (usually some variant of Microsoft BASIC) :

10 PRINT "Hello, world!"20 END

Such implementations of BASIC could also execute instructions in an immediate mode when line numbers are omitted. The following examples work without requiring a RUN instruction.

PRINT "Hello, world!"? "Hello, world!"

Later implementations of BASIC allowed greater support for structured programming and did not require line numbers for source code. The following example works when RUN for the vast majority of modern BASICs.

PRINT "Hello, world!"END

Again, the "END" statement is optional in many BASICs.

PBASIC

DEBUG "Hello, world!", CR

or, the typical microcontroller Hello World program equivalent with the only output device present being a light-emitting diode (LED) (in this case attached to the seventh output pin) :

DO    HIGH 7 'Make the 7th pin go high (turn the LED on)    PAUSE 500 'Sleep for half a second    LOW 7 ' Make the 7th pin go low (turn the LED off)    PAUSE 500 'Sleep for half a secondLOOPEND

StarOffice/OpenOffice Basic

sub main    print "Hello, World"end sub

TI-BASIC

On TI calculators of the TI-80 through TI-86 range:

:Disp "HELLO, WORLD!"           or:Output (x,y,"HELLO, WORLD!")    or:Text (x,y,"HELLO, WORLD!")      or:Text (-1,x,y,"HELLO, WORLD!")   ;only on the 83+ and higher

or simply

:"HELLO, WORLD!"

On TI-89/TI-92 (+) /Voyage 200 calculators:

:hellowld ():Prgm:Disp "Hello, world!":EndPrgm

Visual Basic

Sub Main  MsgBox "Hello World!"End Sub

Visual Basic .NET

Module HelloWorldApp  Sub Main ()     System.Console.WriteLine ("Hello, world!")  End SubEnd Module

or, defined differently,

Class HelloWorldApp  Shared Sub Main ()     System.Console.WriteLine ("Hello, world!")  End SubEnd Class

Blitz BASIC

Print "Hello, World!"

DarkBASIC

PRINT "HELLO WORLD"

TEXT 0,0,"Hello World"WAIT KEY

BCPL

GET "LIBHDR"

LET START () BE$ (    WRITES ("Hello, world!*N")$)

BLISS

%TITLE 'HELLO_WORLD'MODULE HELLO_WORLD (IDENT='V1.0', MAIN=HELLO_WORLD,        ADDRESSING_MODE (EXTERNAL=GENERAL)) =BEGIN    LIBRARY 'SYS$LIBRARY:STARLET';    EXTERNAL ROUTINE       LIB$PUT_OUTPUT;GLOBAL ROUTINE HELLO_WORLD =BEGIN    LIB$PUT_OUTPUT (%ASCID %STRING ('Hello World!'))END;ENDELUDOM

boo

See also GUI Section.

print "Hello, world!"


Casio FX-9750

This program will work on the fx-9750 graphing calculator and compatibles.

"HELLO WORLD"↵

C

#include <stdio.h>int main(){   printf("Hello, world!");   return 0;}

Ch

The above C code can run in Ch as examples. The simple one in Ch is:

 printf ("Hello, world\n") ;


C#

See also GUI Section.

class HelloWorldApp{    static void Main ()    {        System.Console.WriteLine ("Hello, world!") ;    }}

C++

#include <iostream>using namespace std;int main (){    cout << "Hello, world!\n";}

C++/CLI

int main (){   System::Console::WriteLine ("Hello, world!") ;}

C++, Managed (.NET)

#using <mscorlib.dll>using namespace System;int wmain (){    Console::WriteLine ("Hello, world!") ;}

ColdFusion (CFM)

<cfoutput>Hello, world!</cfoutput>

COMAL

PRINT "Hello, World!"

CIL

.method public static void Main () cil managed{     .entrypoint     .maxstack 8     ldstr "Hello, world!"     call void [mscorlib]System.Console::WriteLine (string)     ret}

Clean

module helloStart = "Hello, world"

CLIST

PROC 0WRITE Hello, World!

Clipper

@1,1 say "Hello World!"

COBOL

IDENTIFICATION DIVISION.PROGRAM-ID.     HELLO-WORLD.ENVIRONMENT DIVISION.DATA DIVISION.PROCEDURE DIVISION.DISPLAY "Hello, world!".STOP RUN.


D

import std.stdio;void main (){    writefln ("Hello, world!") ;}

DC an arbitrary precision calculator

[Hello, world!]p

DCL batch

$ write sys$output "Hello, world!"

DOLL

// The program is itself an object. The program "this" object can be overloaded// as a function that work as "main" function in a C program.this (){    system.stdout ("Hello, World!") ;}

Dylan

module: helloformat-out ("Hello, world!\n") ;

Ed and Ex (Ed extended)

ahello world!.p

Eiffel

class HELLO_WORLDcreation    makefeature    make is    local            io:BASIC_IO    do            !!io            io.put_string ("%N Hello, world!")    end -- makeend -- class HELLO_WORLD

Erlang

-module (hello).-export ([hello_world/0]).hello_world () -> io:fwrite ("Hello, world!\n").

Euphoria

puts (1, "Hello, world!")

F#

print_endline "Hello world"

Factor

"Hello world" print

filePro

@once   mesgbox "Hello, world!"   exit

Fjölnir

"hello" < main{   main ->   stef (;)   stofn       skrifastreng (;"Halló Veröld!") ,   stofnlok}*"GRUNNUR";

FOCAL

type "Hello, World!",!

or

t "Hello, World!",!

Focus

-TYPE Hello World

Forte TOOL

begin TOOL HelloWorld;includes Framework;HAS PROPERTY IsLibrary = FALSE;forward  Hello;-- START CLASS DEFINITIONSclass Hello inherits from Framework.Objecthas public  method Init;has property    shared= (allow=off, override=on) ;    transactional= (allow=off, override=on) ;    monitored= (allow=off, override=on) ;    distributed= (allow=off, override=on) ;end class;-- END CLASS DEFINITIONS-- START METHOD DEFINITIONS------------------------------------------------------------method Hello.Initbeginsuper.Init () ;task.Part.LogMgr.PutLine ('HelloWorld!') ;end method;-- END METHOD DEFINITIONSHAS PROPERTY    CompatibilityLevel = 0;    ProjectType = APPLICATION;    Restricted = FALSE;    MultiThreaded = TRUE;    Internal = FALSE;    LibraryName = 'hellowor';    StartingMethod = (class = Hello, method = Init) ;end HelloWorld;

Forth

: halloforth ( -- ) ." Hello, world!" CR ;

FORTRAN

   PROGRAM HELLO     PRINT *, 'Hello, world!'   END

Fril

 ? ((pp "Hello, world!"))

Frink

println["Hello, world!"]

Gambas

See also GUI section.

PUBLIC SUB Main ()  Print "Hello, world!"END

Game Maker

In the draw event of some object:

draw_text (x,y,"Hello World")

Or to show a splash screen message:

show_message ("Hello World")

Haskell

module Main (main) wheremain = putStrLn "Hello World"

or

main = putStrLn "Hello World"

Heron

program HelloWorld;functions {  _main () {    print_string ("Hello, world!") ;  }}end

HP-41 & HP-42S

(Handheld Hewlett-Packard RPN-based alphanumeric engineering calculators.)

01 LBLTHELLO02 THELLO, WORLD03 PROMPT

HyperTalk (Apple HyperCard's scripting programming language)

put "Hello world"

ไฟล์:Hworld.gif

or

Answer "Hello World"

IDL

print,"Hello world!"

Inform

[ Main;  print "Hello, world!^";];

Io

"Hello world!" print

or

write ("Hello world!\n")

Iptscrae

ON ENTER {    "Hello, " "World!" & SAY}

J

Simplest:

 Hello World

Probably closest in semantics:

'Hello World'

Jal

include 16f877_20

 include hd447804  hd44780_clear  hd44780 = "H" hd44780 = "e" hd44780 = "l" hd44780 = "l" hd44780 = "o" hd44780 = " " hd44780 = "W" hd44780 = "o" hd44780 = "r" hd44780 = "l" hd44780 = "d" hd44780 = "!"

Java

See also GUI section.

public class Work_name_or_tag{    public static void main (String[] args)     {        System.out.println ("Hello, world!") ;    }}

Java byte-code

(disassembler output of javap -c Hello.class)

public class Hello extends java.lang.Object {    public Hello () ;    public static void main (java.lang.String[]) ;}Method Hello ()   0 aload_0   1 invokespecial #1 <Method java.lang.Object () >   4 returnMethod void main (java.lang.String[])   0 getstatic #2 <Field java.io.PrintStream out>   3 ldc #3 <String "Hello, world!">   5 invokevirtual #4 <Method void println (java.lang.String) >   8 return

K

`0:"Hello world\n"

Kogut

WriteLine "Hello, world!"

Lisp

Lisp has many dialects that have appeared over its almost fifty-year history.

Common Lisp

(format t "Hello world!~%")

or

(write-line "Hello World!")

or merely:

 "Hello World!"


Scheme


(display "Hello, world!")(newline)

Emacs Lisp

 (print "Hello World")

Logo

print [hello  world!]

or

pr [Hello World!]

In mswlogo only

messagebox [Hi] [Hello World]

Lua

print "Hello, world!"

LuaPSP

screen:print (1,1,"Hello, world!")screen:flip ()

M (MUMPS)

W "Hello, world!"

Macsyma, Maxima

print ("Hello, world!") $

Maple

print ("Hello, World!") ;

Mathematica

Print["Hello World"]

MATLAB

disp ('Hello World')

Max

max v2;#N vpatcher 10 59 610 459;#P message 33 93 63 196617 Hello world!;#P newex 33 73 45 196617 loadbang;#P newex 33 111 31 196617 print;#P connect 1 0 2 0;#P connect 2 0 0 0;#P pop;

Modula-2

MODULE Hello;FROM Terminal2 IMPORT WriteLn; WriteString;BEGIN   WriteString ("Hello, world!") ;   WriteLn;END Hello;

MOO

notify (player, "Hello, world!") ;

MS-DOS batch

(with the standard command.com interpreter. The @ symbol is optional and prevents the system from repeating the command before executing it. The @ symbol must be omitted on versions of MS-DOS prior to 3.0.)

@echo Hello, world!

MUF

: main  me @ "Hello, world!" notify;

Natural

WRITE "Hello, World!"END

Nemerle

The easiest way to get Nemerle print "Hello, world!" would be that:

System.Console.WriteLine ("Hello, world!") ;

however, in bigger applications the following code would be probably more useful:

using System.Console;module HelloWorld{   Main () :void   {      WriteLine ("Hello, world!") ;   }}


Oberon

Oberon is both the name of a programming language and an operating system.

Program written for the Oberon operating system:

MODULE Hello;        IMPORT Oberon, Texts; VAR W: Texts.Writer; PROCEDURE World*; BEGIN   Texts.WriteString (W, "Hello World!") ;   Texts.WriteLn (W) ;   Texts.Append (Oberon.Log, W.buf) END World;BEGIN Texts.OpenWriter (W)END Hello.

Freestanding Oberon program using the standard Oakwood library:

MODULE Hello;   IMPORT Out;BEGIN   Out.String ("Hello World!") ;   Out.LnEND Hello.

Objective C

Functional C Version

#import <stdio.h>int main () {    printf ( "Hello, World!\n" ) ;    return 0;}

Object-Oriented C Version

  1. import <stdio.h>
//An object-oriented version.@interface Hello : Object{   const char str[] = "Hello world";}- (id) hello (void) ;@end@implementation Hello- (id) hello (void){   printf ("%s\n", str) ;}@endint main (void){   Hello *h = [Hello new];   [h hello];      [h free];   return 0;}

OPENSTEP/Cocoa Version

  1. import <Foundation/Foundation.h>
int main (int argc, const char * argv[]){   NSLog (@"Hello, World!") ;   return 0;}

OCaml

print_endline "Hello world!"

OPL

See also GUI section.

PROC hello:  PRINT "Hello, World"ENDP

OPS5

(object-class request         ^action)(startup   (strategy MEA)   (make request ^action hello))(rule hello   (request ^action hello)   (write |Hello World!| (crlf)))

OPS83

module hello (main){  procedure main ( )   {      write () |Hello, world!|, '\n';   };};

Parrot assembly language

print "Hello, world!\n"end

Pascal

program hello (output) ;
begin
writeln ('Hello, world!')
end.


Perl

print "Hello, world!\n";

(This is the first example in Learning Perl; the semicolon is optional.)

Perl 6

say "Hello World";

PHP

Hello, world!

or

<?php echo "Hello, world!\n";?>

or

<?="Hello, world!\n"?>

(Note: This will not work unless short open tags are enabled.)

Pike

int main () {    write ("Hello, world!\n") ;    return 0;}

PL/SQL

-- start anonymous blockset serveroutput on size 10000000;begin    dbms_output.enable (1000000) ;    dbms_output.put_line ('Hello World!') ;end;-- end anonymous block

PL/I

Test: proc options (main) reorder;  put skip edit ('Hello, world!') (a) ;end Test;

POP-11

'Hello world' =>

PostScript

See PDL section

Processing

println ("Hello, world!") ;

Prolog

write ('Hello, world') ,nl.

Python

print "Hello, world!"

หรือใน Python 3.x

print("Hello, world!")

REFAL

$ENTRY GO{=<Prout 'Hello, world!'>;}

REXX, ARexx, NetRexx, and Object REXX

say "Hello, world!"

RPL

See also GUI section.

(On Hewlett-Packard HP-28, HP-48 and HP-49 series graphing calculators.)

<<  CLLCD  "Hello, world!" 1 DISP  0 WAIT  DROP>>

Ruby

See also GUI section.

puts "Hello, world!"

SAS

data _null_;put 'Hello, world!';run;

Sather

class HELLO_WORLD is  main is    #OUT+"Hello, world\n";   end; end;

Scala (programming language)

object HelloWorld with Application {  Console.println ("Hello, world!") ;}

Scriptol

print "Hello world!"

sed

(note: requires at least one line of input)

sed -ne '1s/.*/Hello, world!/p'

Seed7

$ include "seed7_05.s7i";

 const proc: main is func   begin     writeln ("Hello, world!") ;   end func;

Self

'Hello, World!' print.

Simula

BEGIN

    OutText ("Hello, world!") ;    OutImage;END

Smalltalk

Transcript show: 'Hello, world!'; cr

SML

print "Hello, world!\n";

SNOBOL

    OUTPUT = "Hello, world!"END

Span

class Hello {  static public main: args {    Console << "Hello, world!\n";  }}

SPARK

with Spark_IO;--# inherit Spark_IO;--# main_program;procedure Hello_World--# global in out Spark_IO.Outputs;--# derives Spark_IO.Outputs from Spark_IO.Outputs;isbegin  Spark_IO.Put_Line (Spark_IO.Standard_Output, "Hello, world!", 0) ;end Hello_World;

SPITBOL

    OUTPUT = "Hello, world!"END

SQL

CREATE TABLE message (text char (15)) ;INSERT INTO message (text) VALUES ('Hello, world!') ;SELECT text FROM message;DROP TABLE message;

or (e.g. Oracle dialect)

SELECT 'Hello, world!' FROM dual;

or (for Oracle's PL/SQL proprietary procedural language)

BEGIN  DBMS_OUTPUT.ENABLE (1000000) ;  DBMS_OUTPUT.PUT_LINE ('Hello World, from PL/SQL') ;END;

or (e.g. MySQL or PostgreSQL dialect)

SELECT 'Hello, world!';

or (e.g. T-SQL dialect)

PRINT 'Hello, world!'

or (for KB-SQL dialect)

select Null from DATA_DICTIONARY.SQL_QUERYFOOTER or HEADER or DETAIL or FINAL eventwrite "Hello, world!"

STARLET

RACINE: HELLO_WORLD.NOTIONS:HELLO_WORLD : ecrire ("Hello, world!").

TACL

#OUTPUT Hello, world!

Tcl (Tool command language)

See also GUI section.

puts "Hello, world!"

Turing

put "Hello, world!"

TSQL

Declare @Output varchar (16)Set @Output='Hello, world!'Select @Output

or, simpler variations:

Select 'Hello, world!'Print 'Hello, world!'

UNIX-style shell

echo 'Hello, world!'

or

printf '%s' $'Hello, world!\n'

or for a curses interface:

dialog --msgbox 'Hello, world!' 0 0

Visual Prolog console program

#include @"pfc\console\console.ph"goal  console::init () ,  stdio::write ("Hello World!").

ใกล้เคียง

โปรแกรมเฮลโลเวิลด์ โปรแกรมจัดการรหัสผ่าน โปรแกรมหน้า วิญญาณอาฆาต โปรแกรมความภักดี โปรแกรมตรวจแก้จุดบกพร่องกนู โปรแกรมป้องกันไวรัส โปรแกรมประยุกต์ โปรแกรมอรรถประโยชน์ โปรแกรมคอมพิวเตอร์ โปรแกรมประยุกต์บนเว็บ